#include    <stdio.h>
    #include    <stdlib.h>
    #include    <unistd.h>

    int main()
    {
        int pid ;
        int fd;

        printf("About to run who into a file\n");

        if( (pid = fork() ) == -1 ){
            perror("fork"); exit(1);
        }
        if ( pid == 0 ){
            close(1);               /* close, */
            fd = creat( "userlist", 0644 );     /* then open */
            execlp( "who", "who", NULL );       /* and run  */
            perror("execlp");
            exit(1);
        }
        if ( pid != 0 ){
            wait(NULL);
            printf("Done running who.  results in userlist\n");
        }

        return 0;
    }
